
<!DOCTYPE HTML>
<html lang="zh-hans" >
<head>
    <meta charset="UTF-8">
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
    <title>滚动监听及控制ScrollController · 《Flutter实战》</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="baidu-site-verification" content="Y34sAqDKUH"/>
    <meta name="theme-color" content="#ffffff">
    <!--<meta name="description" content="">-->
    <meta name="description" content="《Flutter实战》是Flutter中文网（https://flutterchina.club）开源的电子书，旨在帮助开发者系统化的了解并学习Flutter。">
    <meta name="keywords" content="flutter实战,flutter书籍,flutter电子书,flutter中文网 ">
    <meta name="generator" content="GitBook 3.2.3">
    
    <meta name="author" content="wendux 824783146@qq.com">
    
    
    
    
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/style.css">

    
    
    
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-search-pro/search.css">
    
    
    
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-ace/ace.css">
    
    
    
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-splitter/splitter.css">
    
    
    
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-toggle-chapters/toggle.css">
    
    
    
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-prism/prism.css">
    
    
    
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-donate/plugin.css">
    
    
    
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-fontsettings/website.css">
    
    
    

    

    
        
    
        
    
        
    
        
    
        
    
        
    

    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="../chapter7/" />
    
    
    <link rel="prev" href="custom_scrollview.html" />
    

    <style>
        .pull-right > i {
            font-size: 25px;
            color: #777 !important;
            cursor: pointer;

        }

        .pull-right > i:hover {
            color: #777 !important;
        }

        body {
            font-size: 15px !important;
        }

        a[href='../todo.html'], a[href='todo.html'] {
            color: #888 !important;
        }

        .copyright {
            text-align: center;
            margin: 80px 16px 30px 16px;
            padding-top: 16px;
            border-top: #eee 1px solid;
            color: grey;
            font-size: .9em;
        }

        .ad {
            color: white;
            text-align: center;
            background: url(https://img.alicdn.com/tfs/TB1Huu7vMmTBuNjy1XbXXaMrVXa-2880-400.png);
            background-size: cover;
            cursor: pointer;
            margin-bottom: 30px;
            padding: 18px
        }

        .ad:hover {
            opacity: .8;
        }
    </style>
</head>
<body>
<!--<div id="ad" style="display: none">-->
    <!--<div class="ad ad0"-->
         <!--onclick="_track('aliyun','https://promotion.aliyun.com/ntms/yunparter/invite.html?userCode=8hhi4dts')">-->
        <!--<div style="font-size: 1.3em; padding-right: 120px; position: relative; top: 12px">阿里云新春特惠</div>-->
        <!--<div style="color:orange; font-size: 13px">限时红包 最高￥<span style="font-size: 40px">1888</span></div>-->
    <!--</div>-->
    <!--<div class="ad ad1"-->
         <!--onclick="_track('aliyun-puhui','https://promotion.aliyun.com/ntms/act/qwbk.html?spm=5176.11533457.1089570.10.74e877e33jtaGy&userCode=8hhi4dts')">-->
        <!--<div style="font-size: 1.5em;">阿里云全民云计算-新春特惠</div>-->
        <!--<div style="color:orange; font-size: 18px;padding-top: 4px;">普惠上云，云服务器1核1G仅需293元/年</div>-->
    <!--</div>-->
<!--</div>-->

<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="https://flutterchina.club" target="_blank" class="custom-link"><div><img height=20 style='position:relative; top:5px; padding-right:5px ' src='https://cdn.jsdelivr.net/gh/flutterchina/website@1.0/images/favicon.png'/> Flutter中文网</div></a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    缘起
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../chapter1/">
            
                <a href="../chapter1/">
            
                    
                    起步
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../chapter1/mobile_development_intro.html">
            
                <a href="../chapter1/mobile_development_intro.html">
            
                    
                    移动开发技术简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../chapter1/flutter_intro.html">
            
                <a href="../chapter1/flutter_intro.html">
            
                    
                    Flutter简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../chapter1/install_flutter.html">
            
                <a href="../chapter1/install_flutter.html">
            
                    
                    搭建Flutter开发环境
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../chapter1/configuration.html">
            
                <a href="../chapter1/configuration.html">
            
                    
                    常见配置问题
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="../chapter1/dart.html">
            
                <a href="../chapter1/dart.html">
            
                    
                    Dart语言简介
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../chapter2/">
            
                <a href="../chapter2/">
            
                    
                    第一个Flutter应用
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../chapter2/first_flutter_app.html">
            
                <a href="../chapter2/first_flutter_app.html">
            
                    
                    计数器示例
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../chapter2/flutter_router.html">
            
                <a href="../chapter2/flutter_router.html">
            
                    
                    路由管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../chapter2/flutter_package_mgr.html">
            
                <a href="../chapter2/flutter_package_mgr.html">
            
                    
                    包管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../chapter2/flutter_assets_mgr.html">
            
                <a href="../chapter2/flutter_assets_mgr.html">
            
                    
                    资源管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../chapter2/flutter_app_debug.html">
            
                <a href="../chapter2/flutter_app_debug.html">
            
                    
                    调试Flutter APP
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="../chapter2/thread_model_and_error_report.html">
            
                <a href="../chapter2/thread_model_and_error_report.html">
            
                    
                    Dart线程模型及异常捕获
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../chapter3/">
            
                <a href="../chapter3/">
            
                    
                    基础Widgets
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../chapter3/flutter_widget_intro.html">
            
                <a href="../chapter3/flutter_widget_intro.html">
            
                    
                    Widget简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../chapter3/text.html">
            
                <a href="../chapter3/text.html">
            
                    
                    文本、字体样式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../chapter3/buttons.html">
            
                <a href="../chapter3/buttons.html">
            
                    
                    按钮
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../chapter3/img_and_icon.html">
            
                <a href="../chapter3/img_and_icon.html">
            
                    
                    图片和Icon
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../chapter3/radio_and_checkbox.html">
            
                <a href="../chapter3/radio_and_checkbox.html">
            
                    
                    单选框和复选框
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="../chapter3/input_and_form.html">
            
                <a href="../chapter3/input_and_form.html">
            
                    
                    输入框和表单
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../chapter4/">
            
                <a href="../chapter4/">
            
                    
                    布局类Widgets
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../chapter4/intro.html">
            
                <a href="../chapter4/intro.html">
            
                    
                    布局类Widgets简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../chapter4/row_and_column.html">
            
                <a href="../chapter4/row_and_column.html">
            
                    
                    线性布局Row、Column
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../chapter4/flex.html">
            
                <a href="../chapter4/flex.html">
            
                    
                    弹性布局Flex
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../chapter4/wrap_and_flow.html">
            
                <a href="../chapter4/wrap_and_flow.html">
            
                    
                    流式布局Wrap、Flow
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="../chapter4/stack.html">
            
                <a href="../chapter4/stack.html">
            
                    
                    层叠布局Stack、Positioned
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../chapter5/">
            
                <a href="../chapter5/">
            
                    
                    容器类Widgets
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../chapter5/padding.html">
            
                <a href="../chapter5/padding.html">
            
                    
                    Padding
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../chapter5/constrainedbox_and_sizebox.html">
            
                <a href="../chapter5/constrainedbox_and_sizebox.html">
            
                    
                    布局限制类容器ConstrainedBox、SizeBox
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../chapter5/decoratedbox.html">
            
                <a href="../chapter5/decoratedbox.html">
            
                    
                    装饰容器DecoratedBox
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../chapter5/transform.html">
            
                <a href="../chapter5/transform.html">
            
                    
                    变换Transform
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../chapter5/container.html">
            
                <a href="../chapter5/container.html">
            
                    
                    Container容器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="../chapter5/material_scaffold.html">
            
                <a href="../chapter5/material_scaffold.html">
            
                    
                    Scaffold、TabBar、底部导航
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="./">
            
                <a href="./">
            
                    
                    可滚动Widgets
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="intro.html">
            
                <a href="intro.html">
            
                    
                    可滚动Widgets简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="single_child_scrollview.html">
            
                <a href="single_child_scrollview.html">
            
                    
                    SingleChildScrollView
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="listview.html">
            
                <a href="listview.html">
            
                    
                    ListView
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="gridview.html">
            
                <a href="gridview.html">
            
                    
                    GridView
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.5" data-path="custom_scrollview.html">
            
                <a href="custom_scrollview.html">
            
                    
                    CustomScrollView
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.7.6" data-path="scroll_controller.html">
            
                <a href="scroll_controller.html">
            
                    
                    滚动监听及控制ScrollController
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../chapter7/">
            
                <a href="../chapter7/">
            
                    
                    功能型Widgets
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../chapter7/willpopscope.html">
            
                <a href="../chapter7/willpopscope.html">
            
                    
                    导航返回拦截-WillPopScope
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../chapter7/inherited_widget.html">
            
                <a href="../chapter7/inherited_widget.html">
            
                    
                    数据共享-InheritedWidget
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="../chapter7/theme.html">
            
                <a href="../chapter7/theme.html">
            
                    
                    主题-Theme
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../chapter8/">
            
                <a href="../chapter8/">
            
                    
                    事件处理与通知
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../chapter8/listener.html">
            
                <a href="../chapter8/listener.html">
            
                    
                    原始指针事件处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="../chapter8/gesture.html">
            
                <a href="../chapter8/gesture.html">
            
                    
                    手势识别
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.3" data-path="../chapter8/eventbus.html">
            
                <a href="../chapter8/eventbus.html">
            
                    
                    全局事件总线
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4" data-path="../chapter8/notification.html">
            
                <a href="../chapter8/notification.html">
            
                    
                    通知Notification
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../chapter9/">
            
                <a href="../chapter9/">
            
                    
                    动画
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../chapter9/intro.html">
            
                <a href="../chapter9/intro.html">
            
                    
                    Flutter动画简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" data-path="../chapter9/animation_structure.html">
            
                <a href="../chapter9/animation_structure.html">
            
                    
                    动画结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.3" data-path="../chapter9/route_transition.html">
            
                <a href="../chapter9/route_transition.html">
            
                    
                    自定义路由过渡动画
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.4" data-path="../chapter9/hero.html">
            
                <a href="../chapter9/hero.html">
            
                    
                    Hero动画
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.5" data-path="../chapter9/stagger_animation.html">
            
                <a href="../chapter9/stagger_animation.html">
            
                    
                    交错动画
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../chapter13/">
            
                <a href="../chapter13/">
            
                    
                    自定义Widget
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" data-path="../chapter13/intro.html">
            
                <a href="../chapter13/intro.html">
            
                    
                    自定义Widget方法简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2" data-path="../chapter13/combine.html">
            
                <a href="../chapter13/combine.html">
            
                    
                    通过组合现有Widget实现
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.3" data-path="../chapter13/turn_box.html">
            
                <a href="../chapter13/turn_box.html">
            
                    
                    实例：TurnBox
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.4" data-path="../chapter13/custom_paint.html">
            
                <a href="../chapter13/custom_paint.html">
            
                    
                    CustomPaint与Canvas
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.5" data-path="../chapter13/gradient_circular_progress_demo.html">
            
                <a href="../chapter13/gradient_circular_progress_demo.html">
            
                    
                    实例：圆形渐变进度条(自绘)
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../chapter10/">
            
                <a href="../chapter10/">
            
                    
                    文件操作与网络请求
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.12.1" data-path="../chapter10/file_operation.html">
            
                <a href="../chapter10/file_operation.html">
            
                    
                    文件操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.2" data-path="../chapter10/http.html">
            
                <a href="../chapter10/http.html">
            
                    
                    Http请求-HttpClient
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.3" data-path="../chapter10/dio.html">
            
                <a href="../chapter10/dio.html">
            
                    
                    Http请求-Dio package
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.4" data-path="../chapter10/download_with_chunks.html">
            
                <a href="../chapter10/download_with_chunks.html">
            
                    
                    实例：Http分块下载
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.5" data-path="../chapter10/websocket.html">
            
                <a href="../chapter10/websocket.html">
            
                    
                    WebSocket
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.6" data-path="../chapter10/socket.html">
            
                <a href="../chapter10/socket.html">
            
                    
                    使用Socket API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.7" data-path="../chapter10/json_model.html">
            
                <a href="../chapter10/json_model.html">
            
                    
                    Json转Model
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../chapter11/">
            
                <a href="../chapter11/">
            
                    
                    包与插件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.13.1" data-path="../chapter11/develop_package.html">
            
                <a href="../chapter11/develop_package.html">
            
                    
                    开发package
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.2" data-path="../chapter11/platform-channel.html">
            
                <a href="../chapter11/platform-channel.html">
            
                    
                    插件开发：平台通道简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.3" data-path="../chapter11/android_implement.html">
            
                <a href="../chapter11/android_implement.html">
            
                    
                    插件开发：实现Android端API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.4" data-path="../chapter11/ios_implement.html">
            
                <a href="../chapter11/ios_implement.html">
            
                    
                    插件开发：实现IOS端API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.5" data-path="../todo.html">
            
                <a href="../todo.html">
            
                    
                    系统能力调用
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="../chapter12/">
            
                <a href="../chapter12/">
            
                    
                    国际化
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.14.1" data-path="../chapter12/multi_languages_support.html">
            
                <a href="../chapter12/multi_languages_support.html">
            
                    
                    让App支持多语言
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.2" data-path="../chapter12/locallization_implement.html">
            
                <a href="../chapter12/locallization_implement.html">
            
                    
                    实现Localizations
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.3" data-path="../chapter12/intl.html">
            
                <a href="../chapter12/intl.html">
            
                    
                    使用Intl包
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="../chapter14/">
            
                <a href="../chapter14/">
            
                    
                    Flutter核心原理
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.15.1" data-path="../chapter14/flutter_ui_system.html">
            
                <a href="../chapter14/flutter_ui_system.html">
            
                    
                    Flutter UI系统
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.2" data-path="../chapter14/element_buildcontext.html">
            
                <a href="../chapter14/element_buildcontext.html">
            
                    
                    Element和BuildContext
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.3" data-path="../chapter14/render_object.html">
            
                <a href="../chapter14/render_object.html">
            
                    
                    RenderObject与RenderBox
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.4" data-path="../chapter14/flutter_app_startup.html">
            
                <a href="../chapter14/flutter_app_startup.html">
            
                    
                    Flutter从启动到显示
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="../todo.html">
            
                <a href="../todo.html">
            
                    
                    Flutter资源汇总
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    
    <a class="btn pull-right" aria-label="GitHub">
        <i class="fa fa-edit" title="编辑本文"></i>
    </a>
    <a class="btn pull-right" aria-label="GitHub" href="https://github.com/flutterchina/flutter-in-action">
        <i class="fa fa-github" title="查看本书开源项目"></i>
    </a>
    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >滚动监听及控制ScrollController</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h2 id="&#x6EDA;&#x52A8;&#x76D1;&#x542C;&#x53CA;&#x63A7;&#x5236;">&#x6EDA;&#x52A8;&#x76D1;&#x542C;&#x53CA;&#x63A7;&#x5236;</h2>
<p>&#x5728;&#x524D;&#x51E0;&#x8282;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x4ECB;&#x7ECD;&#x4E86;Flutter&#x4E2D;&#x5E38;&#x7528;&#x7684;&#x53EF;&#x6EDA;&#x52A8;Widget&#xFF0C;&#x4E5F;&#x8BF4;&#x8FC7;&#x53EF;&#x4EE5;&#x7528;ScrollController&#x6765;&#x63A7;&#x5236;&#x53EF;&#x6EDA;&#x52A8;widget&#x7684;&#x6EDA;&#x52A8;&#x4F4D;&#x7F6E;&#xFF0C;&#x672C;&#x8282;&#x5148;&#x4ECB;&#x7ECD;&#x4E00;&#x4E0B;ScrollController&#xFF0C;&#x7136;&#x540E;&#x4EE5;ListView&#x4E3A;&#x4F8B;&#xFF0C;&#x5C55;&#x793A;&#x4E00;&#x4E0B;ScrollController&#x7684;&#x5177;&#x4F53;&#x7528;&#x6CD5;&#x3002;&#x6700;&#x540E;&#xFF0C;&#x518D;&#x4ECB;&#x7ECD;&#x4E00;&#x4E0B;&#x8DEF;&#x7531;&#x5207;&#x6362;&#x65F6;&#x5982;&#x4F55;&#x6765;&#x4FDD;&#x5B58;&#x6EDA;&#x52A8;&#x4F4D;&#x7F6E;&#x3002;</p>
<h3 id="scrollcontroller">ScrollController</h3>
<p>&#x6784;&#x9020;&#x51FD;&#x6570;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart"><span class="token function">ScrollController</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
  double initialScrollOffset <span class="token operator">=</span> <span class="token number">0.0</span><span class="token punctuation">,</span> <span class="token comment">//&#x521D;&#x59CB;&#x6EDA;&#x52A8;&#x4F4D;&#x7F6E;</span>
  <span class="token keyword">this</span><span class="token punctuation">.</span>keepScrollOffset <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">,</span><span class="token comment">//&#x662F;&#x5426;&#x4FDD;&#x5B58;&#x6EDA;&#x52A8;&#x4F4D;&#x7F6E;</span>
  <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre>
<p>&#x6211;&#x4EEC;&#x4ECB;&#x7ECD;&#x4E00;&#x4E0B;ScrollController&#x5E38;&#x7528;&#x7684;&#x5C5E;&#x6027;&#x548C;&#x65B9;&#x6CD5;&#xFF1A;</p>
<ul>
<li><code>offset</code>&#xFF1A;&#x53EF;&#x6EDA;&#x52A8;Widget&#x5F53;&#x524D;&#x6EDA;&#x52A8;&#x7684;&#x4F4D;&#x7F6E;&#x3002;</li>
<li><code>jumpTo(double offset)</code>&#x3001;<code>animateTo(double offset,...)</code>&#xFF1A;&#x8FD9;&#x4E24;&#x4E2A;&#x65B9;&#x6CD5;&#x7528;&#x4E8E;&#x8DF3;&#x8F6C;&#x5230;&#x6307;&#x5B9A;&#x7684;&#x4F4D;&#x7F6E;&#xFF0C;&#x5B83;&#x4EEC;&#x4E0D;&#x540C;&#x4E4B;&#x5904;&#x5728;&#x4E8E;&#xFF0C;&#x540E;&#x8005;&#x5728;&#x8DF3;&#x8F6C;&#x65F6;&#x4F1A;&#x6267;&#x884C;&#x4E00;&#x4E2A;&#x52A8;&#x753B;&#xFF0C;&#x800C;&#x524D;&#x8005;&#x4E0D;&#x4F1A;&#x3002;</li>
</ul>
<p>ScrollController&#x8FD8;&#x6709;&#x4E00;&#x4E9B;&#x5C5E;&#x6027;&#x548C;&#x65B9;&#x6CD5;&#xFF0C;&#x6211;&#x4EEC;&#x5C06;&#x5728;&#x540E;&#x9762;&#x539F;&#x7406;&#x90E8;&#x5206;&#x89E3;&#x91CA;&#x3002;</p>
<h4 id="&#x6EDA;&#x52A8;&#x76D1;&#x542C;">&#x6EDA;&#x52A8;&#x76D1;&#x542C;</h4>
<p>ScrollController&#x95F4;&#x63A5;&#x7EE7;&#x627F;&#x81EA;Listenable&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x6839;&#x636E;ScrollController&#x6765;&#x76D1;&#x542C;&#x6EDA;&#x52A8;&#x4E8B;&#x4EF6;&#x3002;&#x5982;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart">controller<span class="token punctuation">.</span><span class="token function">addListener</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">=</span><span class="token operator">&gt;</span><span class="token function">print</span><span class="token punctuation">(</span>controller<span class="token punctuation">.</span>offset<span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre>
<h3 id="&#x793A;&#x4F8B;">&#x793A;&#x4F8B;</h3>
<p>&#x6211;&#x4EEC;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;ListView&#xFF0C;&#x5F53;&#x6EDA;&#x52A8;&#x4F4D;&#x7F6E;&#x53D1;&#x751F;&#x53D8;&#x5316;&#x65F6;&#xFF0C;&#x6211;&#x4EEC;&#x5148;&#x6253;&#x5370;&#x51FA;&#x5F53;&#x524D;&#x6EDA;&#x52A8;&#x4F4D;&#x7F6E;&#xFF0C;&#x7136;&#x540E;&#x5224;&#x65AD;&#x5F53;&#x524D;&#x4F4D;&#x7F6E;&#x662F;&#x5426;&#x8D85;&#x8FC7;1000&#x50CF;&#x7D20;&#xFF0C;&#x5982;&#x679C;&#x8D85;&#x8FC7;&#x5219;&#x5728;&#x5C4F;&#x5E55;&#x53F3;&#x4E0B;&#x89D2;&#x663E;&#x793A;&#x4E00;&#x4E2A;&#x201C;&#x8FD4;&#x56DE;&#x9876;&#x90E8;&#x201D;&#x7684;&#x6309;&#x94AE;&#xFF0C;&#x8BE5;&#x6309;&#x94AE;&#x70B9;&#x51FB;&#x540E;&#x53EF;&#x4EE5;&#x4F7F;ListView&#x6062;&#x590D;&#x5230;&#x521D;&#x59CB;&#x4F4D;&#x7F6E;&#xFF1B;&#x5982;&#x679C;&#x6CA1;&#x6709;&#x8D85;&#x8FC7;1000&#x50CF;&#x7D20;&#xFF0C;&#x5219;&#x9690;&#x85CF;&#x201C;&#x8FD4;&#x56DE;&#x9876;&#x90E8;&#x201D;&#x6309;&#x94AE;&#x3002;&#x4EE3;&#x7801;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart">
<span class="token keyword">class</span> <span class="token class-name">ScrollControllerTestRoute</span> <span class="token keyword">extends</span> <span class="token class-name">StatefulWidget</span> <span class="token punctuation">{</span>
  <span class="token metadata symbol">@override</span>
  ScrollControllerTestRouteState <span class="token function">createState</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">ScrollControllerTestRouteState</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token keyword">class</span> <span class="token class-name">ScrollControllerTestRouteState</span> <span class="token keyword">extends</span> <span class="token class-name">State</span><span class="token operator">&lt;</span>ScrollControllerTestRoute<span class="token operator">&gt;</span> <span class="token punctuation">{</span>
  ScrollController _controller <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ScrollController</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  bool showToTopBtn <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">;</span> <span class="token comment">//&#x662F;&#x5426;&#x663E;&#x793A;&#x201C;&#x8FD4;&#x56DE;&#x5230;&#x9876;&#x90E8;&#x201D;&#x6309;&#x94AE;</span>

  <span class="token metadata symbol">@override</span>
  <span class="token keyword">void</span> <span class="token function">initState</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">//&#x76D1;&#x542C;&#x6EDA;&#x52A8;&#x4E8B;&#x4EF6;&#xFF0C;&#x6253;&#x5370;&#x6EDA;&#x52A8;&#x4F4D;&#x7F6E;</span>
    _controller<span class="token punctuation">.</span><span class="token function">addListener</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token function">print</span><span class="token punctuation">(</span>_controller<span class="token punctuation">.</span>offset<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//&#x6253;&#x5370;&#x6EDA;&#x52A8;&#x4F4D;&#x7F6E;</span>
      <span class="token keyword">if</span> <span class="token punctuation">(</span>_controller<span class="token punctuation">.</span>offset <span class="token operator">&lt;</span> <span class="token number">1000</span> <span class="token operator">&amp;&amp;</span> showToTopBtn<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token function">setState</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
          showToTopBtn <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>_controller<span class="token punctuation">.</span>offset <span class="token operator">&gt;=</span> <span class="token number">1000</span> <span class="token operator">&amp;&amp;</span> showToTopBtn <span class="token operator">==</span> <span class="token boolean">false</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token function">setState</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
          showToTopBtn <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token punctuation">}</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>

  <span class="token metadata symbol">@override</span>
  <span class="token keyword">void</span> <span class="token function">dispose</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">//&#x4E3A;&#x4E86;&#x907F;&#x514D;&#x5185;&#x5B58;&#x6CC4;&#x9732;&#xFF0C;&#x9700;&#x8981;&#x8C03;&#x7528;_controller.dispose</span>
    _controller<span class="token punctuation">.</span><span class="token function">dispose</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">super</span><span class="token punctuation">.</span><span class="token function">dispose</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>

  <span class="token metadata symbol">@override</span>
  Widget <span class="token function">build</span><span class="token punctuation">(</span>BuildContext context<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token function">Scaffold</span><span class="token punctuation">(</span>
      appBar<span class="token punctuation">:</span> <span class="token function">AppBar</span><span class="token punctuation">(</span>title<span class="token punctuation">:</span> <span class="token function">Text</span><span class="token punctuation">(</span><span class="token string">&quot;&#x6EDA;&#x52A8;&#x63A7;&#x5236;&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
      body<span class="token punctuation">:</span> <span class="token function">Scrollbar</span><span class="token punctuation">(</span>
        child<span class="token punctuation">:</span> ListView<span class="token punctuation">.</span><span class="token function">builder</span><span class="token punctuation">(</span>
            itemCount<span class="token punctuation">:</span> <span class="token number">100</span><span class="token punctuation">,</span>
            itemExtent<span class="token punctuation">:</span> <span class="token number">50.0</span><span class="token punctuation">,</span> <span class="token comment">//&#x5217;&#x8868;&#x9879;&#x9AD8;&#x5EA6;&#x56FA;&#x5B9A;&#x65F6;&#xFF0C;&#x663E;&#x5F0F;&#x6307;&#x5B9A;&#x9AD8;&#x5EA6;&#x662F;&#x4E00;&#x4E2A;&#x597D;&#x4E60;&#x60EF;(&#x6027;&#x80FD;&#x6D88;&#x8017;&#x5C0F;)</span>
            controller<span class="token punctuation">:</span> _controller<span class="token punctuation">,</span>
            itemBuilder<span class="token punctuation">:</span> <span class="token punctuation">(</span>context<span class="token punctuation">,</span> index<span class="token punctuation">)</span> <span class="token punctuation">{</span>
              <span class="token keyword">return</span> <span class="token function">ListTile</span><span class="token punctuation">(</span>title<span class="token punctuation">:</span> <span class="token function">Text</span><span class="token punctuation">(</span><span class="token string">&quot;$index&quot;</span><span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">)</span><span class="token punctuation">,</span>
      <span class="token punctuation">)</span><span class="token punctuation">,</span>
      floatingActionButton<span class="token punctuation">:</span> <span class="token operator">!</span>showToTopBtn <span class="token operator">?</span> <span class="token keyword">null</span> <span class="token punctuation">:</span> <span class="token function">FloatingActionButton</span><span class="token punctuation">(</span>
          child<span class="token punctuation">:</span> <span class="token function">Icon</span><span class="token punctuation">(</span>Icons<span class="token punctuation">.</span>arrow_upward<span class="token punctuation">)</span><span class="token punctuation">,</span>
          onPressed<span class="token punctuation">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token comment">//&#x8FD4;&#x56DE;&#x5230;&#x9876;&#x90E8;&#x65F6;&#x6267;&#x884C;&#x52A8;&#x753B;</span>
            _controller<span class="token punctuation">.</span><span class="token function">animateTo</span><span class="token punctuation">(</span><span class="token number">.0</span><span class="token punctuation">,</span>
                duration<span class="token punctuation">:</span> <span class="token function">Duration</span><span class="token punctuation">(</span>milliseconds<span class="token punctuation">:</span> <span class="token number">200</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                curve<span class="token punctuation">:</span> Curves<span class="token punctuation">.</span>ease
            <span class="token punctuation">)</span><span class="token punctuation">;</span>
          <span class="token punctuation">}</span>
      <span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x4EE3;&#x7801;&#x8BF4;&#x660E;&#x5DF2;&#x7ECF;&#x5305;&#x542B;&#x5728;&#x6CE8;&#x91CA;&#x91CC;&#xFF0C;&#x4E0B;&#x9762;&#x6211;&#x4EEC;&#x770B;&#x770B;&#x8FD0;&#x884C;&#x6548;&#x679C;&#xFF1A;</p>
<p><img src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action@1.0/docs/imgs/Screenshot_1536817558.png" alt="Screenshot_1536817558"><img src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action@1.0/docs/imgs/Screenshot_1536817570.png" alt="Screenshot_1536817570"></p>
<p>&#x7531;&#x4E8E;&#x5217;&#x8868;&#x9879;&#x9AD8;&#x5EA6;&#x4E3A;50&#x50CF;&#x7D20;&#xFF0C;&#x5F53;&#x6ED1;&#x52A8;&#x5230;&#x7B2C;20&#x4E2A;&#x5217;&#x8868;&#x9879;&#x540E;&#xFF0C;&#x53F3;&#x4E0B;&#x89D2;&#x201C;&#x8FD4;&#x56DE;&#x9876;&#x90E8;&#x201D;&#x6309;&#x94AE;&#x4F1A;&#x663E;&#x793A;&#xFF0C;&#x70B9;&#x51FB;&#x8BE5;&#x6309;&#x94AE;&#xFF0C;ListView&#x4F1A;&#x5728;&#x8FD4;&#x56DE;&#x9876;&#x90E8;&#x7684;&#x8FC7;&#x7A0B;&#x4E2D;&#x6267;&#x884C;&#x4E00;&#x4E2A;&#x6EDA;&#x52A8;&#x52A8;&#x753B;&#xFF0C;&#x52A8;&#x753B;&#x65F6;&#x95F4;&#x662F;200&#x6BEB;&#x79D2;&#xFF0C;&#x52A8;&#x753B;&#x66F2;&#x7EBF;&#x662F;Curves.ease&#xFF0C;&#x5173;&#x4E8E;&#x52A8;&#x753B;&#x7684;&#x8BE6;&#x7EC6;&#x5185;&#x5BB9;&#x6211;&#x4EEC;&#x5C06;&#x5728;&#x540E;&#x9762;&#x201C;&#x52A8;&#x753B;&#x201D;&#x4E00;&#x7AE0;&#x4E2D;&#x8BE6;&#x7EC6;&#x4ECB;&#x7ECD;&#x3002;</p>
<h3 id="&#x6EDA;&#x52A8;&#x4F4D;&#x7F6E;&#x6062;&#x590D;">&#x6EDA;&#x52A8;&#x4F4D;&#x7F6E;&#x6062;&#x590D;</h3>
<p>PageStorage&#x662F;&#x4E00;&#x4E2A;&#x7528;&#x4E8E;&#x4FDD;&#x5B58;&#x9875;&#x9762;(&#x8DEF;&#x7531;)&#x76F8;&#x5173;&#x6570;&#x636E;&#x7684;Widget&#xFF0C;&#x5B83;&#x5E76;&#x4E0D;&#x4F1A;&#x5F71;&#x54CD;&#x5B50;&#x6811;&#x7684;UI&#x5916;&#x89C2;&#xFF0C;&#x5176;&#x5B9E;&#xFF0C;PageStorage&#x662F;&#x4E00;&#x4E2A;&#x529F;&#x80FD;&#x578B;Widget&#xFF0C;&#x5B83;&#x62E5;&#x6709;&#x4E00;&#x4E2A;&#x5B58;&#x50A8;&#x6876;&#xFF08;bucket&#xFF09;&#xFF0C;&#x5B50;&#x6811;&#x4E2D;&#x7684;Widget&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x6307;&#x5B9A;&#x4E0D;&#x540C;&#x7684;PageStorageKey&#x6765;&#x5B58;&#x50A8;&#x5404;&#x81EA;&#x7684;&#x6570;&#x636E;&#x6216;&#x72B6;&#x6001;&#x3002;</p>
<p>&#x6BCF;&#x6B21;&#x6EDA;&#x52A8;&#x7ED3;&#x675F;&#xFF0C;Scrollable Widget&#x90FD;&#x4F1A;&#x5C06;&#x6EDA;&#x52A8;&#x4F4D;&#x7F6E;<code>offset</code>&#x5B58;&#x50A8;&#x5230;PageStorage&#x4E2D;&#xFF0C;&#x5F53;Scrollable Widget &#x91CD;&#x65B0;&#x521B;&#x5EFA;&#x65F6;&#x518D;&#x6062;&#x590D;&#x3002;&#x5982;&#x679C;<code>ScrollController.keepScrollOffset</code>&#x4E3A;<code>false</code>&#xFF0C;&#x5219;&#x6EDA;&#x52A8;&#x4F4D;&#x7F6E;&#x5C06;&#x4E0D;&#x4F1A;&#x88AB;&#x5B58;&#x50A8;&#xFF0C;Scrollable Widget&#x91CD;&#x65B0;&#x521B;&#x5EFA;&#x65F6;&#x4F1A;&#x4F7F;&#x7528;<code>ScrollController.initialScrollOffset</code>&#xFF1B;<code>ScrollController.keepScrollOffset</code>&#x4E3A;<code>true</code>&#x65F6;&#xFF0C;Scrollable Widget&#x5728;<strong>&#x7B2C;&#x4E00;&#x6B21;</strong>&#x521B;&#x5EFA;&#x65F6;&#xFF0C;&#x4F1A;&#x6EDA;&#x52A8;&#x5230;<code>initialScrollOffset</code>&#x5904;&#xFF0C;&#x56E0;&#x4E3A;&#x8FD9;&#x65F6;&#x8FD8;&#x6CA1;&#x6709;&#x5B58;&#x50A8;&#x8FC7;&#x6EDA;&#x52A8;&#x4F4D;&#x7F6E;&#x3002;&#x5728;&#x63A5;&#x4E0B;&#x6765;&#x7684;&#x6EDA;&#x52A8;&#x4E2D;&#x5C31;&#x4F1A;&#x5B58;&#x50A8;&#x3001;&#x6062;&#x590D;&#x6EDA;&#x52A8;&#x4F4D;&#x7F6E;&#xFF0C;&#x800C;<code>initialScrollOffset</code>&#x4F1A;&#x88AB;&#x5FFD;&#x7565;&#x3002;</p>
<p>&#x5F53;&#x4E00;&#x4E2A;&#x8DEF;&#x7531;&#x4E2D;&#x5305;&#x542B;&#x591A;&#x4E2A;Scrollable Widget&#x65F6;&#xFF0C;&#x5982;&#x679C;&#x4F60;&#x53D1;&#x73B0;&#x5728;&#x8FDB;&#x884C;&#x4E00;&#x4E9B;&#x8DF3;&#x8F6C;&#x6216;&#x5207;&#x6362;&#x64CD;&#x4F5C;&#x540E;&#xFF0C;&#x6EDA;&#x52A8;&#x4F4D;&#x7F6E;&#x4E0D;&#x80FD;&#x6B63;&#x786E;&#x6062;&#x590D;&#xFF0C;&#x8FD9;&#x65F6;&#x4F60;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x663E;&#x5F0F;&#x6307;&#x5B9A;PageStorageKey&#x6765;&#x5206;&#x522B;&#x8DDF;&#x8E2A;&#x4E0D;&#x540C;Scrollable Widget&#x7684;&#x4F4D;&#x7F6E;&#xFF0C;&#x5982;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart"><span class="token function">ListView</span><span class="token punctuation">(</span>key<span class="token punctuation">:</span> <span class="token function">PageStorageKey</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
<span class="token function">ListView</span><span class="token punctuation">(</span>key<span class="token punctuation">:</span> <span class="token function">PageStorageKey</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
<p>&#x4E0D;&#x540C;&#x7684;PageStorageKey&#xFF0C;&#x9700;&#x8981;&#x4E0D;&#x540C;&#x7684;&#x503C;&#xFF0C;&#x8FD9;&#x6837;&#x624D;&#x53EF;&#x4EE5;&#x533A;&#x5206;&#x4E3A;&#x4E0D;&#x540C;Scrollable Widget&#x4FDD;&#x5B58;&#x7684;&#x6EDA;&#x52A8;&#x4F4D;&#x7F6E;&#x3002;</p>
<blockquote>
<p>&#x6CE8;&#x610F;&#xFF1A;&#x4E00;&#x4E2A;&#x8DEF;&#x7531;&#x4E2D;&#x5305;&#x542B;&#x591A;&#x4E2A;Scrollable Widget&#x65F6;&#xFF0C;&#x5982;&#x679C;&#x8981;&#x5206;&#x522B;&#x8DDF;&#x8E2A;&#x5B83;&#x4EEC;&#x7684;&#x6EDA;&#x52A8;&#x4F4D;&#x7F6E;&#xFF0C;&#x5E76;&#x975E;&#x4E00;&#x5B9A;&#x5C31;&#x5F97;&#x7ED9;&#x4ED6;&#x4EEC;&#x5206;&#x522B;&#x63D0;&#x4F9B;PageStorageKey&#x3002;&#x8FD9;&#x662F;&#x56E0;&#x4E3A;Scrollable&#x672C;&#x8EAB;&#x662F;&#x4E00;&#x4E2A;StatefulWidget&#xFF0C;&#x5B83;&#x7684;&#x72B6;&#x6001;&#x4E2D;&#x4E5F;&#x4F1A;&#x4FDD;&#x5B58;&#x5F53;&#x524D;&#x6EDA;&#x52A8;&#x4F4D;&#x7F6E;&#xFF0C;&#x6240;&#x4EE5;&#xFF0C;&#x53EA;&#x8981;Scrollable Widget&#x672C;&#x8EAB;&#x6CA1;&#x6709;&#x88AB;&#x4ECE;&#x6811;&#x4E0A;detach&#x6389;&#xFF0C;&#x90A3;&#x4E48;&#x5176;State&#x5C31;&#x4E0D;&#x4F1A;&#x9500;&#x6BC1;(dispose)&#xFF0C;&#x6EDA;&#x52A8;&#x4F4D;&#x7F6E;&#x5C31;&#x4E0D;&#x4F1A;&#x4E22;&#x5931;&#x3002;&#x53EA;&#x6709;&#x5F53;Widget&#x53D1;&#x751F;&#x7ED3;&#x6784;&#x53D8;&#x5316;&#xFF0C;&#x5BFC;&#x81F4;Scrollable Widget&#x7684;State&#x9500;&#x6BC1;&#x6216;&#x91CD;&#x65B0;&#x6784;&#x5EFA;&#x65F6;&#x624D;&#x4F1A;&#x4E22;&#x5931;&#x72B6;&#x6001;&#xFF0C;&#x8FD9;&#x79CD;&#x60C5;&#x51B5;&#x5C31;&#x9700;&#x8981;&#x663E;&#x5F0F;&#x6307;&#x5B9A;PageStorageKey&#xFF0C;&#x901A;&#x8FC7;PageStorage&#x6765;&#x5B58;&#x50A8;&#x6EDA;&#x52A8;&#x4F4D;&#x7F6E;&#xFF0C;&#x4E00;&#x4E2A;&#x5178;&#x578B;&#x7684;&#x573A;&#x666F;&#x662F;&#x5728;&#x4F7F;&#x7528;TabBarView&#x65F6;&#xFF0C;&#x5728;Tab&#x53D1;&#x751F;&#x5207;&#x6362;&#x65F6;&#xFF0C;Tab&#x9875;&#x4E2D;&#x7684;Scrollable Widget&#x7684;State&#x5C31;&#x4F1A;&#x9500;&#x6BC1;&#xFF0C;&#x8FD9;&#x65F6;&#x5982;&#x679C;&#x60F3;&#x6062;&#x590D;&#x6EDA;&#x52A8;&#x4F4D;&#x7F6E;&#x5C31;&#x9700;&#x8981;&#x6307;&#x5B9A;PageStorageKey&#x3002;</p>
</blockquote>
<h3 id="scrollposition">ScrollPosition</h3>
<p>&#x4E00;&#x4E2A;ScrollController&#x53EF;&#x4EE5;&#x540C;&#x65F6;&#x88AB;&#x591A;&#x4E2A;Scrollable Widget&#x4F7F;&#x7528;&#xFF0C;ScrollController&#x4F1A;&#x4E3A;&#x6BCF;&#x4E00;&#x4E2A;Scrollable Widget&#x521B;&#x5EFA;&#x4E00;&#x4E2A;ScrollPosition&#x5BF9;&#x8C61;&#xFF0C;&#x8FD9;&#x4E9B;ScrollPosition&#x4FDD;&#x5B58;&#x5728;ScrollController&#x7684;<code>positions</code>&#x5C5E;&#x6027;&#x4E2D;&#xFF08;List<scrollposition>&#xFF09;&#x3002;ScrollPosition&#x662F;&#x771F;&#x6B63;&#x4FDD;&#x5B58;&#x6ED1;&#x52A8;&#x4F4D;&#x7F6E;&#x4FE1;&#x606F;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;<code>offset</code>&#x53EA;&#x662F;&#x4E00;&#x4E2A;&#x4FBF;&#x6377;&#x5C5E;&#x6027;&#xFF1A;</scrollposition></p>
<pre class="language-"><code class="lang-dart">double <span class="token keyword">get</span> offset <span class="token operator">=</span><span class="token operator">&gt;</span> position<span class="token punctuation">.</span>pixels<span class="token punctuation">;</span>
</code></pre>
<p>&#x4E00;&#x4E2A;ScrollController&#x867D;&#x7136;&#x53EF;&#x4EE5;&#x5BF9;&#x5E94;&#x591A;&#x4E2A;Scrollable Widget&#xFF0C;&#x4F46;&#x662F;&#x6709;&#x4E00;&#x4E9B;&#x64CD;&#x4F5C;&#xFF0C;&#x5982;&#x8BFB;&#x53D6;&#x6EDA;&#x52A8;&#x4F4D;&#x7F6E;<code>offset</code>&#xFF0C;&#x5219;&#x9700;&#x8981;&#x4E00;&#x5BF9;&#x4E00;&#xFF0C;&#x4F46;&#x662F;&#x6211;&#x4EEC;&#x4ECD;&#x7136;&#x53EF;&#x4EE5;&#x5728;&#x4E00;&#x5BF9;&#x591A;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x901A;&#x8FC7;&#x5176;&#x5B83;&#x65B9;&#x6CD5;&#x8BFB;&#x53D6;&#x6EDA;&#x52A8;&#x4F4D;&#x7F6E;&#xFF0C;&#x4E3E;&#x4E2A;&#x4F8B;&#x5B50;&#xFF0C;&#x5047;&#x8BBE;&#x4E00;&#x4E2A;ScrollController&#x540C;&#x65F6;&#x88AB;&#x4E24;&#x4E2A;Scrollable Widget&#x4F7F;&#x7528;&#xFF0C;&#x90A3;&#x4E48;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x5982;&#x4E0B;&#x65B9;&#x5F0F;&#x5206;&#x522B;&#x8BFB;&#x53D6;&#x4ED6;&#x4EEC;&#x7684;&#x6EDA;&#x52A8;&#x4F4D;&#x7F6E;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart"><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
controller<span class="token punctuation">.</span>positions<span class="token punctuation">.</span><span class="token function">elementAt</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">.</span>pixels
controller<span class="token punctuation">.</span>positions<span class="token punctuation">.</span><span class="token function">elementAt</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">.</span>pixels
<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
</code></pre>
<p>&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;<code>controller.positions.length</code>&#x6765;&#x786E;&#x5B9A;<code>controller</code>&#x88AB;&#x51E0;&#x4E2A;Scrollable Widget&#x4F7F;&#x7528;&#x3002;</p>
<h4 id="&#x65B9;&#x6CD5;">&#x65B9;&#x6CD5;</h4>
<p>ScrollPosition&#x6709;&#x4E24;&#x4E2A;&#x5E38;&#x7528;&#x65B9;&#x6CD5;&#xFF1A;<code>animateTo()</code> &#x548C; <code>jumpTo()</code>&#xFF0C;&#x5B83;&#x4EEC;&#x662F;&#x771F;&#x6B63;&#x6765;&#x63A7;&#x5236;&#x8DF3;&#x8F6C;&#x6EDA;&#x52A8;&#x4F4D;&#x7F6E;&#x7684;&#x65B9;&#x6CD5;&#xFF0C;ScrollController&#x7684;&#x8FD9;&#x4E24;&#x4E2A;&#x540C;&#x540D;&#x65B9;&#x6CD5;&#xFF0C;&#x5185;&#x90E8;&#x6700;&#x7EC8;&#x90FD;&#x4F1A;&#x8C03;&#x7528;ScrollPosition&#x7684;&#x3002;</p>
<h3 id="scrollcontroller&#x63A7;&#x5236;&#x539F;&#x7406;">ScrollController&#x63A7;&#x5236;&#x539F;&#x7406;</h3>
<p>&#x6211;&#x4EEC;&#x6765;&#x4ECB;&#x7ECD;&#x4E00;&#x4E0B;ScrollController&#x7684;&#x53E6;&#x5916;&#x4E09;&#x4E2A;&#x65B9;&#x6CD5;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart">ScrollPosition <span class="token function">createScrollPosition</span><span class="token punctuation">(</span>
    ScrollPhysics physics<span class="token punctuation">,</span>
    ScrollContext context<span class="token punctuation">,</span>
    ScrollPosition oldPosition<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">void</span> <span class="token function">attach</span><span class="token punctuation">(</span>ScrollPosition position<span class="token punctuation">)</span> <span class="token punctuation">;</span>
<span class="token keyword">void</span> <span class="token function">detach</span><span class="token punctuation">(</span>ScrollPosition position<span class="token punctuation">)</span> <span class="token punctuation">;</span>
</code></pre>
<p>&#x5F53;ScrollController&#x548C;Scrollable Widget&#x5173;&#x8054;&#x65F6;&#xFF0C;Scrollable Widget&#x9996;&#x5148;&#x4F1A;&#x8C03;&#x7528;ScrollController&#x7684;<code>createScrollPosition()</code>&#x65B9;&#x6CD5;&#x6765;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;ScrollPosition&#x6765;&#x5B58;&#x50A8;&#x6EDA;&#x52A8;&#x4F4D;&#x7F6E;&#x4FE1;&#x606F;&#xFF0C;&#x63A5;&#x7740;&#xFF0C;Scrollable Widget&#x4F1A;&#x8C03;&#x7528;<code>attach()</code>&#x65B9;&#x6CD5;&#xFF0C;&#x5C06;&#x521B;&#x5EFA;&#x7684;ScrollPosition&#x6DFB;&#x52A0;&#x5230;ScrollController&#x7684;<code>positions</code>&#x5C5E;&#x6027;&#x4E2D;&#xFF0C;&#x8FD9;&#x4E00;&#x6B65;&#x79F0;&#x4E3A;&#x201C;&#x6CE8;&#x518C;&#x4F4D;&#x7F6E;&#x201D;&#xFF0C;&#x53EA;&#x6709;&#x6CE8;&#x518C;&#x540E;<code>animateTo()</code> &#x548C; <code>jumpTo()</code>&#x624D;&#x53EF;&#x4EE5;&#x88AB;&#x8C03;&#x7528;&#x3002;&#x5F53;Scrollable Widget&#x9500;&#x6BC1;&#x65F6;&#xFF0C;&#x4F1A;&#x8C03;&#x7528;ScrollController&#x7684;<code>detach()</code>&#x65B9;&#x6CD5;&#xFF0C;&#x5C06;&#x5176;ScrollPosition&#x5BF9;&#x8C61;&#x4ECE;ScrollController&#x7684;<code>positions</code>&#x5C5E;&#x6027;&#x4E2D;&#x79FB;&#x9664;&#xFF0C;&#x8FD9;&#x4E00;&#x6B65;&#x79F0;&#x4E3A;&#x201C;&#x6CE8;&#x9500;&#x4F4D;&#x7F6E;&#x201D;&#xFF0C;&#x6CE8;&#x9500;&#x540E;<code>animateTo()</code> &#x548C; <code>jumpTo()</code> &#x5C06;&#x4E0D;&#x80FD;&#x518D;&#x88AB;&#x8C03;&#x7528;&#x3002;</p>
<p>&#x9700;&#x8981;&#x6CE8;&#x610F;&#x7684;&#x662F;&#xFF0C;ScrollController&#x7684;<code>animateTo()</code> &#x548C; <code>jumpTo()</code>&#x5185;&#x90E8;&#x4F1A;&#x8C03;&#x7528;&#x6240;&#x6709;ScrollPosition&#x7684;<code>animateTo()</code> &#x548C; <code>jumpTo()</code>&#xFF0C;&#x4EE5;&#x5B9E;&#x73B0;&#x6240;&#x6709;&#x548C;&#x8BE5;ScrollController&#x5173;&#x8054;&#x7684;Scrollable Widget&#x90FD;&#x6EDA;&#x52A8;&#x5230;&#x6307;&#x5B9A;&#x7684;&#x4F4D;&#x7F6E;&#x3002;</p>
<h2 id="&#x6EDA;&#x52A8;&#x76D1;&#x542C;">&#x6EDA;&#x52A8;&#x76D1;&#x542C;</h2>
<p>Flutter Widget&#x6811;&#x4E2D;&#x5B50;Widget&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x53D1;&#x9001;&#x901A;&#x77E5;&#xFF08;Notification&#xFF09;&#x4E0E;&#x7236;(&#x5305;&#x62EC;&#x7956;&#x5148;)Widget&#x901A;&#x4FE1;&#x3002;&#x7236;Widget&#x53EF;&#x4EE5;&#x901A;&#x8FC7;NotificationListener Widget&#x6765;&#x76D1;&#x542C;&#x81EA;&#x5DF1;&#x5173;&#x6CE8;&#x7684;&#x901A;&#x77E5;&#xFF0C;&#x8FD9;&#x79CD;&#x901A;&#x4FE1;&#x65B9;&#x5F0F;&#x7C7B;&#x4F3C;&#x4E8E;Web&#x5F00;&#x53D1;&#x4E2D;&#x6D4F;&#x89C8;&#x5668;&#x7684;&#x4E8B;&#x4EF6;&#x5192;&#x6CE1;&#xFF0C;&#x6211;&#x4EEC;&#x5728;Flutter&#x4E2D;&#x6CBF;&#x7528;&#x201C;&#x5192;&#x6CE1;&#x201D;&#x8FD9;&#x4E2A;&#x672F;&#x8BED;&#x3002;Scrollable Widget&#x5728;&#x6EDA;&#x52A8;&#x65F6;&#x4F1A;&#x53D1;&#x9001;ScrollNotification&#x7C7B;&#x578B;&#x7684;&#x901A;&#x77E5;&#xFF0C;ScrollBar&#x6B63;&#x662F;&#x901A;&#x8FC7;&#x76D1;&#x542C;&#x6EDA;&#x52A8;&#x901A;&#x77E5;&#x6765;&#x5B9E;&#x73B0;&#x7684;&#x3002;&#x901A;&#x8FC7;NotificationListener&#x76D1;&#x542C;&#x6EDA;&#x52A8;&#x4E8B;&#x4EF6;&#x548C;&#x901A;&#x8FC7;ScrollController&#x6709;&#x4E24;&#x4E2A;&#x4E3B;&#x8981;&#x7684;&#x4E0D;&#x540C;&#xFF1A;</p>
<ol>
<li>&#x901A;&#x8FC7;NotificationListener&#x53EF;&#x4EE5;&#x5728;&#x4ECE;Scrollable Widget&#x5230;Widget&#x6811;&#x6839;&#x4E4B;&#x95F4;&#x4EFB;&#x610F;&#x4F4D;&#x7F6E;&#x90FD;&#x80FD;&#x76D1;&#x542C;&#x3002;&#x800C;ScrollController&#x53EA;&#x80FD;&#x548C;&#x5177;&#x4F53;&#x7684;Scrollable Widget&#x5173;&#x8054;&#x540E;&#x624D;&#x53EF;&#x4EE5;&#x3002;</li>
<li>&#x6536;&#x5230;&#x6EDA;&#x52A8;&#x4E8B;&#x4EF6;&#x540E;&#x83B7;&#x5F97;&#x7684;&#x4FE1;&#x606F;&#x4E0D;&#x540C;&#xFF1B;NotificationListener&#x5728;&#x6536;&#x5230;&#x6EDA;&#x52A8;&#x4E8B;&#x4EF6;&#x65F6;&#xFF0C;&#x901A;&#x77E5;&#x4E2D;&#x4F1A;&#x643A;&#x5E26;&#x5F53;&#x524D;&#x6EDA;&#x52A8;&#x4F4D;&#x7F6E;&#x548C;ViewPort&#x7684;&#x4E00;&#x4E9B;&#x4FE1;&#x606F;&#xFF0C;&#x800C;ScrollController&#x53EA;&#x80FD;&#x83B7;&#x53D6;&#x5F53;&#x524D;&#x6EDA;&#x52A8;&#x4F4D;&#x7F6E;&#x3002;</li>
</ol>
<h3 id="notificationlistener">NotificationListener<t></t></h3>
<p>NotificationListener<t>&#x662F;&#x4E00;&#x4E2A;Widget&#xFF0C;&#x6A21;&#x677F;&#x53C2;&#x6570;T&#x662F;&#x60F3;&#x76D1;&#x542C;&#x7684;&#x901A;&#x77E5;&#x7C7B;&#x578B;&#xFF0C;&#x5982;&#x679C;&#x7701;&#x7565;&#xFF0C;&#x5219;&#x6240;&#x6709;&#x7C7B;&#x578B;&#x901A;&#x77E5;&#x90FD;&#x4F1A;&#x88AB;&#x76D1;&#x542C;&#xFF0C;&#x5982;&#x679C;&#x6307;&#x5B9A;&#x7279;&#x5B9A;&#x7C7B;&#x578B;&#xFF0C;&#x5219;&#x53EA;&#x6709;&#x8BE5;&#x7C7B;&#x578B;&#x7684;&#x901A;&#x77E5;&#x4F1A;&#x88AB;&#x76D1;&#x542C;&#x3002;NotificationListener&#x9700;&#x8981;&#x4E00;&#x4E2A;onNotification&#x56DE;&#x8C03;&#x51FD;&#x6570;&#xFF0C;&#x7528;&#x4E8E;&#x5B9E;&#x73B0;&#x76D1;&#x542C;&#x5904;&#x7406;&#x903B;&#x8F91;&#xFF0C;&#x8BE5;&#x56DE;&#x8C03;&#x53EF;&#x4EE5;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x5E03;&#x5C14;&#x503C;&#xFF0C;&#x4EE3;&#x8868;&#x662F;&#x5426;&#x963B;&#x6B62;&#x8BE5;&#x4E8B;&#x4EF6;&#x7EE7;&#x7EED;&#x5411;&#x4E0A;&#x5192;&#x6CE1;&#xFF0C;&#x5982;&#x679C;&#x4E3A;<code>true</code>&#x65F6;&#xFF0C;&#x5219;&#x5192;&#x6CE1;&#x7EC8;&#x6B62;&#xFF0C;&#x4E8B;&#x4EF6;&#x505C;&#x6B62;&#x5411;&#x4E0A;&#x4F20;&#x64AD;&#xFF0C;&#x5982;&#x679C;&#x4E0D;&#x8FD4;&#x56DE;&#x6216;&#x8005;&#x8FD4;&#x56DE;&#x503C;&#x4E3A;<code>false</code> &#x65F6;&#xFF0C;&#x5219;&#x5192;&#x6CE1;&#x7EE7;&#x7EED;&#x3002;</t></p>
<h3 id="&#x793A;&#x4F8B;">&#x793A;&#x4F8B;</h3>
<p>&#x4E0B;&#x9762;&#xFF0C;&#x6211;&#x4EEC;&#x76D1;&#x542C;ListView&#x7684;&#x6EDA;&#x52A8;&#x901A;&#x77E5;&#xFF0C;&#x7136;&#x540E;&#x663E;&#x793A;&#x5F53;&#x524D;&#x6EDA;&#x52A8;&#x8FDB;&#x5EA6;&#x767E;&#x5206;&#x6BD4;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart"><span class="token keyword">import</span> <span class="token string">&apos;package:flutter/material.dart&apos;</span><span class="token punctuation">;</span>

<span class="token keyword">class</span> <span class="token class-name">ScrollNotificationTestRoute</span> <span class="token keyword">extends</span> <span class="token class-name">StatefulWidget</span> <span class="token punctuation">{</span>
  <span class="token metadata symbol">@override</span>
  _ScrollNotificationTestRouteState <span class="token function">createState</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span>
      <span class="token keyword">new</span> <span class="token class-name">_ScrollNotificationTestRouteState</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token keyword">class</span> <span class="token class-name">_ScrollNotificationTestRouteState</span>
    <span class="token keyword">extends</span> <span class="token class-name">State</span><span class="token operator">&lt;</span>ScrollNotificationTestRoute<span class="token operator">&gt;</span> <span class="token punctuation">{</span>
  String _progress <span class="token operator">=</span> <span class="token string">&quot;0%&quot;</span><span class="token punctuation">;</span> <span class="token comment">//&#x4FDD;&#x5B58;&#x8FDB;&#x5EA6;&#x767E;&#x5206;&#x6BD4;</span>

  <span class="token metadata symbol">@override</span>
  Widget <span class="token function">build</span><span class="token punctuation">(</span>BuildContext context<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token function">Scrollbar</span><span class="token punctuation">(</span> <span class="token comment">//&#x8FDB;&#x5EA6;&#x6761;</span>
      <span class="token comment">// &#x76D1;&#x542C;&#x6EDA;&#x52A8;&#x901A;&#x77E5;</span>
      child<span class="token punctuation">:</span> NotificationListener<span class="token operator">&lt;</span>ScrollNotification<span class="token operator">&gt;</span><span class="token punctuation">(</span>
        onNotification<span class="token punctuation">:</span> <span class="token punctuation">(</span>ScrollNotification notification<span class="token punctuation">)</span> <span class="token punctuation">{</span>
          double progress <span class="token operator">=</span> notification<span class="token punctuation">.</span>metrics<span class="token punctuation">.</span>pixels <span class="token operator">/</span>
              notification<span class="token punctuation">.</span>metrics<span class="token punctuation">.</span>maxScrollExtent<span class="token punctuation">;</span>
          <span class="token comment">//&#x91CD;&#x65B0;&#x6784;&#x5EFA;</span>
          <span class="token function">setState</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            _progress <span class="token operator">=</span> <span class="token string">&quot;${(progress * 100).toInt()}%&quot;</span><span class="token punctuation">;</span>
          <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
          <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&quot;BottomEdge: ${notification.metrics.extentAfter == 0}&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
          <span class="token comment">//return true; //&#x653E;&#x5F00;&#x6B64;&#x884C;&#x6CE8;&#x91CA;&#x540E;&#xFF0C;&#x8FDB;&#x5EA6;&#x6761;&#x5C06;&#x5931;&#x6548;</span>
        <span class="token punctuation">}</span><span class="token punctuation">,</span>
        child<span class="token punctuation">:</span> <span class="token function">Stack</span><span class="token punctuation">(</span>
          alignment<span class="token punctuation">:</span> Alignment<span class="token punctuation">.</span>center<span class="token punctuation">,</span>
          children<span class="token punctuation">:</span> <span class="token operator">&lt;</span>Widget<span class="token operator">&gt;</span><span class="token punctuation">[</span>
            ListView<span class="token punctuation">.</span><span class="token function">builder</span><span class="token punctuation">(</span>
                itemCount<span class="token punctuation">:</span> <span class="token number">100</span><span class="token punctuation">,</span>
                itemExtent<span class="token punctuation">:</span> <span class="token number">50.0</span><span class="token punctuation">,</span>
                itemBuilder<span class="token punctuation">:</span> <span class="token punctuation">(</span>context<span class="token punctuation">,</span> index<span class="token punctuation">)</span> <span class="token punctuation">{</span>
                  <span class="token keyword">return</span> <span class="token function">ListTile</span><span class="token punctuation">(</span>title<span class="token punctuation">:</span> <span class="token function">Text</span><span class="token punctuation">(</span><span class="token string">&quot;$index&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token punctuation">}</span>
            <span class="token punctuation">)</span><span class="token punctuation">,</span>
            <span class="token function">CircleAvatar</span><span class="token punctuation">(</span>  <span class="token comment">//&#x663E;&#x793A;&#x8FDB;&#x5EA6;&#x767E;&#x5206;&#x6BD4;</span>
              radius<span class="token punctuation">:</span> <span class="token number">30.0</span><span class="token punctuation">,</span>
              child<span class="token punctuation">:</span> <span class="token function">Text</span><span class="token punctuation">(</span>_progress<span class="token punctuation">)</span><span class="token punctuation">,</span>
              backgroundColor<span class="token punctuation">:</span> Colors<span class="token punctuation">.</span>black54<span class="token punctuation">,</span>
            <span class="token punctuation">)</span>
          <span class="token punctuation">]</span><span class="token punctuation">,</span>
        <span class="token punctuation">)</span><span class="token punctuation">,</span>
      <span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x6211;&#x4EEC;&#x770B;&#x4E00;&#x770B;&#x8FD0;&#x884C;&#x7ED3;&#x679C;&#xFF1A;</p>
<p><img src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action@1.0/docs/imgs/image-20180913165011407.png" alt="image-20180913165011407"></p>
<p>&#x5728;&#x63A5;&#x6536;&#x5230;&#x6EDA;&#x52A8;&#x4E8B;&#x4EF6;&#x65F6;&#xFF0C;&#x53C2;&#x6570;&#x7C7B;&#x578B;&#x4E3A;ScrollNotification&#xFF0C;&#x5B83;&#x5305;&#x62EC;&#x4E00;&#x4E2A;<code>metrics</code>&#x5C5E;&#x6027;&#xFF0C;&#x5B83;&#x7684;&#x7C7B;&#x578B;&#x662F;ScrollMetrics&#xFF0C;&#x8BE5;&#x5C5E;&#x6027;&#x5305;&#x542B;&#x5F53;&#x524D;ViewPort&#x53CA;&#x6EDA;&#x52A8;&#x4F4D;&#x7F6E;&#x7B49;&#x4FE1;&#x606F;&#xFF1A;</p>
<ul>
<li>pixels&#xFF1A;&#x5F53;&#x524D;&#x6EDA;&#x52A8;&#x4F4D;&#x7F6E;&#x3002;</li>
<li>maxScrollExtent&#xFF1A;&#x6700;&#x5927;&#x53EF;&#x6EDA;&#x52A8;&#x957F;&#x5EA6;&#x3002;</li>
<li>extentBefore&#xFF1A;&#x6ED1;&#x51FA;ViewPort&#x9876;&#x90E8;&#x7684;&#x957F;&#x5EA6;&#xFF1B;&#x6B64;&#x793A;&#x4F8B;&#x4E2D;&#x76F8;&#x5F53;&#x4E8E;&#x9876;&#x90E8;&#x6ED1;&#x51FA;&#x5C4F;&#x5E55;&#x4E0A;&#x65B9;&#x7684;&#x5217;&#x8868;&#x957F;&#x5EA6;&#x3002;</li>
<li>extentInside&#xFF1A;ViewPort&#x5185;&#x90E8;&#x957F;&#x5EA6;&#xFF1B;&#x6B64;&#x793A;&#x4F8B;&#x4E2D;&#x5C4F;&#x5E55;&#x663E;&#x793A;&#x7684;&#x5217;&#x8868;&#x90E8;&#x5206;&#x7684;&#x957F;&#x5EA6;&#x3002;</li>
<li>extentAfter&#xFF1A;&#x5217;&#x8868;&#x4E2D;&#x672A;&#x6ED1;&#x5165;ViewPort&#x90E8;&#x5206;&#x7684;&#x957F;&#x5EA6;&#xFF1B;&#x6B64;&#x793A;&#x4F8B;&#x4E2D;&#x5217;&#x8868;&#x5E95;&#x90E8;&#x672A;&#x663E;&#x793A;&#x5230;&#x5C4F;&#x5E55;&#x8303;&#x56F4;&#x90E8;&#x5206;&#x7684;&#x957F;&#x5EA6;&#x3002;</li>
<li>atEdge&#xFF1A;&#x662F;&#x5426;&#x6ED1;&#x5230;&#x4E86;Scrollable Widget&#x7684;&#x8FB9;&#x754C;&#xFF08;&#x6B64;&#x793A;&#x4F8B;&#x4E2D;&#x76F8;&#x5F53;&#x4E8E;&#x5217;&#x8868;&#x9876;&#x6216;&#x5E95;&#x90E8;&#xFF09;&#x3002;</li>
</ul>
<p>ScrollMetrics&#x8FD8;&#x6709;&#x4E00;&#x4E9B;&#x5176;&#x5B83;&#x5C5E;&#x6027;&#xFF0C;&#x8BFB;&#x8005;&#x53EF;&#x4EE5;&#x81EA;&#x884C;&#x67E5;&#x9605;API&#x6587;&#x6863;&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="custom_scrollview.html" class="navigation navigation-prev " aria-label="Previous page: CustomScrollView">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="../chapter7/" class="navigation navigation-next " aria-label="Next page: 功能型Widgets">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"滚动监听及控制ScrollController","level":"1.7.6","depth":2,"next":{"title":"功能型Widgets","level":"1.8","depth":1,"path":"chapter7/index.md","ref":"chapter7/index.md","articles":[{"title":"导航返回拦截-WillPopScope","level":"1.8.1","depth":2,"path":"chapter7/willpopscope.md","ref":"chapter7/willpopscope.md","articles":[]},{"title":"数据共享-InheritedWidget","level":"1.8.2","depth":2,"path":"chapter7/inherited_widget.md","ref":"chapter7/inherited_widget.md","articles":[]},{"title":"主题-Theme","level":"1.8.3","depth":2,"path":"chapter7/theme.md","ref":"chapter7/theme.md","articles":[]}]},"previous":{"title":"CustomScrollView","level":"1.7.5","depth":2,"path":"chapter6/custom_scrollview.md","ref":"chapter6/custom_scrollview.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-search","search-pro","ace","splitter","toggle-chapters","prism","donate","-highlight"],"root":"docs","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"prism":{"lang":{"shell":"bash"}},"ace":{},"splitter":{},"search-pro":{"cutWordLib":"nodejieba","defineWord":["Gitbook Use"]},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"donate":{"alipay":"","alipayText":"支付宝打赏","button":"赏","title":"","wechat":"https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action@1.0.3/docs/imgs/pay.jpeg","wechatText":"微信打赏"},"fontsettings":{"theme":"white","family":"sans","size":2},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"toggle-chapters":{}},"theme":"default","author":"wendux 824783146@qq.com","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"《Flutter实战》","language":"zh-hans","links":{"sharing":{"all":null,"facebook":null,"google":null,"twitter":null,"weibo":null},"sidebar":{"<div><img height=20 style='position:relative; top:5px; padding-right:5px ' src='https://cdn.jsdelivr.net/gh/flutterchina/website@1.0/images/favicon.png'/> Flutter中文网</div>":"https://flutterchina.club"}},"gitbook":"*","description":"记录Gitbook的配置和一些插件的使用"},"file":{"path":"chapter6/scroll_controller.md","mtime":"2019-01-02T10:06:06.486Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-05-14T10:32:57.346Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>



    <script src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook.js"></script>
    <script src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/theme.js"></script>
    
        
        <script src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-ace/ace/ace.js"></script>
        
    
        
        <script src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-ace/ace.js"></script>
        
    
        
        <script src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-toggle-chapters/toggle.js"></script>
        
    
        
        <script src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-donate/plugin.js"></script>
        
    
        
        <script src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    


<script>
    var _hmt = _hmt || [];
    $("#bd").remove();
    (function () {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?170231fea4f81697eb046edc1a91fe5b";
        var s = document.getElementsByTagName("script")[0];
        hm.id = "bd"
        s.parentNode.insertBefore(hm, s);
    })();

    function init() {
        var p = location.pathname;
        _hmt.push(['_trackPageview', p]);
        if (p[p.length - 1] === '/') {
            p += "index.md"
        } else {
            p = p.split(".")[0] + ".md";
        }
        p = "https://github.com/flutterchina/flutter-in-action/blob/master/docs" + p;
        $(".pull-right .fa-edit").parent("a").attr("href", p);
        $("table").wrap("<div style='overflow: auto'></div>");
        //百度统计
        var e = /([http|https]:\/\/[a-zA-Z0-9\_\.]+\.baidu\.com)/gi, r = window.location.href,
            t = document.referrer;
        if (!e.test(r)) {
            var o = "https://sp0.baidu.com/9_Q4simg2RQJ8t7jm9iCKT-xh_/s.gif";
            t ? (o += "?r=" + encodeURIComponent(document.referrer), r && (o += "&l=" + r)) : r && (o += "?l=" + r);
            var i = new Image;
            i.src = o
        }
        $(".copyright").remove();
        $("<div class='copyright'> 本书仍在勘误阶段，请勿以任何形式私自传播，作者保留对本书的版权。</div>").appendTo(".page-inner");
    }

    function hookAPI(api, ob, fn) {
        return function () {
            var result = api.apply(ob, [].slice.call(arguments));

            setTimeout(fn, 1000);
            return result;
        }
    }

    function addAD() {
        if (location.href !== 'https://book.flutterchina.club/' && $("#book-search-results .ad").length == 0) {
            var id=Math.ceil(Math.random()*10)%2;
            $(".ad"+id).clone().hide().fadeIn().prependTo("#book-search-results")
            setTimeout(function () {
                $(".body-inner").animate({scrollTop: 0}, 200)
            }, 800);
        }
    }

    function _track(p,url) {
        _hmt.push(['_trackEvent', 'ad', 'click', p]);
        setTimeout(function () {
            location.href = url
        }, 100);
    }

    // setInterval(addAD, 300);

    init();


    if (history.pushState) {
        history.pushState = hookAPI(history.pushState, history, init);
    }

</script>
</body>

</html>

